<!DOCTYPE HTML>
<html>
<head>
    <title>部落帖子管理</title>
    <link rel="stylesheet" href="/stylesheets/style.css">
    <script src="/scripts/jquery.min.js"></script>
    <script src="/scripts/boot.js" type="text/javascript"></script>
    <link rel="stylesheet" href="/scripts/miniui/themes/default/miniui.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/icons.css">
    <link rel="stylesheet" href="/scripts/miniui/themes/bootstrap/skin.css">
    <link rel="stylesheet" href="/editor/common.css">
    <script src="/scripts/miniui/miniui.js"></script>
</head>
<body  style="padding: 0;width: 100%;height: 98%">
<!--<div class="mini-splitter" style="width:100%;height:100%;">-->
<!--</div>-->
<div style="width:100%;height: 97%;">
    <div id="outImg">
        <img id="imgId" src="" alt="" onclick="smallImg()">
    </div>
    <div style="padding: 5px">
        <span>子品牌ID：</span><input  class="mini-textbox" type="text" id="objectId"/>
        <span>所属部落ID：</span><input  class="mini-textbox" type="text" id="tribeOId"/>
        <span>帖子内容：</span><input  class="mini-textbox" type="text" id="content"/>
        <span>所属部落名称：</span><input  class="mini-textbox" type="text" id="tribeName"/>
        <span>创建人ID：</span><input  class="mini-textbox" type="text" id="userOId"/>
        <span>创建人昵称：</span><input  class="mini-textbox" type="text" id="nickName"/>

        <a class="mini-button" iconCls="icon-search" onclick="search()">查找</a>
    </div>
    <div style="width:99%;">
        <div class="mini-toolbar" style="border-bottom:0;padding:0px;">
            <table style="width:100%;">
                <tr>
                    <td style="width:100%;">
                        <a class="mini-button" iconCls="icon-remove" onclick="remove()">全部删除</a>
                    </td>
                </tr>
            </table>
        </div>
    </div>

    <div id="datagrid1" class="mini-datagrid" style="width:99%;height: 96%;" multiSelect="true"
         url="/tribeRoute/child/brand" idField="id" allowResize="true" onshowrowdetail="onShowRowDetail"
         sizeList="[20,30,50,100]" pageSize="20"
    >
        <!--allowCellEdit="true" allowCellSelect="true" multiSelect="true"-->
        <div property="columns">
            <div type="checkcolumn" ></div>
            <div type="expandcolumn" >#</div>
            <div field="tribeOId" width="100" align="center" headerAlign="center">部落Id</div>
            <div field="tribeName" width="80" align="center" headerAlign="center">部落名</div>
            <div field="userOId" width="100" align="center" headerAlign="center">创建人Id</div>
            <div field="userName" width="80" align="center" headerAlign="center">创建人</div>
            <div field="isCanShare" width="40" align="center" headerAlign="center">能否分享</div>
            <div field="title" width="100" align="center" headerAlign="center">标题</div>
            <div field="isTop" width="40" align="center" headerAlign="center">是否置顶</div>
            <div field="enjoyNum" width="40" align="center" headerAlign="center">点赞数</div>
            <div field="hotNum" width="40" align="center" headerAlign="center">浏览数</div>
            <div field="status" width="50" align="center" headerAlign="center">状态</div>
            <div field="picName" width="50" align="center" headerAlign="center">封面图</div>
            <div field="createdAt" width="70" align="center" headerAlign="center" >创建日期</div>
            <div field="updatedAt" width="70" align="center" headerAlign="center" >更新日期</div>
        </div>
    </div>
    <div id="editForm1" style="display:none;">
        <div  class="mini-tabs" style="width:100%;" activeIndex="0">
            <div title="子品牌内容" style="width:100%">
                <table style="width:100%;">
                    <tr style="height: 50px">
                        <td>帖子内容：<textarea style="width: 95%; height: 400px;" name="content" class="mini-textarea"></textarea></td>
                    </tr>
                </table>
            </div>
            <div title="关联商品">
                <div id="datagrid2" class="mini-datagrid" style="width:99%;height: 200px;"
                     url="/getdata/relateGoodsInformation" idField="id" allowResize="true"
                     sizeList="[20,30,50,100]" pageSize="10"
                >
                    <div property="columns">
                        <div type="checkcolumn" ></div>
                        <div field="objectId" width="120" headerAlign="center" allowSort="true" >objectId</div>
                        <div field="title" width="80" headerAlign="center" allowSort="true" >商品名称</div>
                        <div field="shopIcon"  width="70" align="center" headerAlign="center" renderer="onGenderRenderer" allowSort="true" >商品iocn</div>
                        <div field="status" renderer="statusRenderer" align="center" width="50" headerAlign="center" allowSort="true">商品状态</div>
                        <div field="groupBuying" renderer="groupBuyingRenderer" align="center" width="50" headerAlign="center" allowSort="true">能否团购</div>
                        <div field="freePost" renderer="freePostRenderer" align="center" headerAlign="center" width="50" allowSort="true" >包邮</div>
                        <div field="promotePrice" align="center" width="50" headerAlign="center" allowSort="true">推广佣金</div>
                        <div field="shopName"  width="100" align="center" headerAlign="center" allowSort="true">店铺名称</div>
                        <div field="groupPrice" align="center" headerAlign="center" width="50" allowSort="true" >团购价格</div>
                        <div field="saleNums" align="center" headerAlign="center" width="40" allowSort="true" >销量</div>
                        <div field="originalPrice" align="center" headerAlign="center" width="40" allowSort="true" >原价</div>
                        <div field="describe" align="center" headerAlign="center" width="100" allowSort="true" >商品描述</div>
                        <div field="discount" align="center" headerAlign="center" width="50" allowSort="true" >商品折扣</div>
                        <div field="price" align="center" headerAlign="center" width="50" allowSort="true" >价格</div>
                        <div field="customize" renderer="customizeRenderer" align="center" headerAlign="center" width="70" allowSort="true" >能否订制</div>
                        <div field="stock" align="center" headerAlign="center" width="50" allowSort="true" >库存</div>
                        <div field="createdAt" width="100" align="center" headerAlign="center"  allowSort="true">创建日期</div>
                        <div field="updatedAt" width="100" align="center" headerAlign="center"  allowSort="true">更新日期</div>
                    </div>
                </div>
            </div>
            <div title="关联团购商品">
                <div id="datagrid3" class="mini-datagrid" style="width:99%;height: 200px;"
                     url="/getdata/relateGoodsInformation" idField="id" allowResize="true"
                     sizeList="[20,30,50,100]" pageSize="10"
                >
                    <div property="columns">
                        <div type="checkcolumn" ></div>
                        <div field="objectId" width="120" headerAlign="center" allowSort="true" >objectId</div>
                        <div field="title" width="80" headerAlign="center" allowSort="true" >商品名称</div>
                        <div field="shopIcon"  width="70" align="center" headerAlign="center" renderer="onGenderRenderer" allowSort="true" >商品iocn</div>
                        <div field="status" renderer="statusRenderer" align="center" width="50" headerAlign="center" allowSort="true">商品状态</div>
                        <div field="groupBuying" renderer="groupBuyingRenderer" align="center" width="50" headerAlign="center" allowSort="true">能否团购</div>
                        <div field="freePost" renderer="freePostRenderer" align="center" headerAlign="center" width="50" allowSort="true" >包邮</div>
                        <div field="promotePrice" align="center" width="50" headerAlign="center" allowSort="true">推广佣金</div>
                        <div field="shopName"  width="100" align="center" headerAlign="center" allowSort="true">店铺名称</div>
                        <div field="groupPrice" align="center" headerAlign="center" width="50" allowSort="true" >团购价格</div>
                        <div field="saleNums" align="center" headerAlign="center" width="40" allowSort="true" >销量</div>
                        <div field="originalPrice" align="center" headerAlign="center" width="40" allowSort="true" >原价</div>
                        <div field="describe" align="center" headerAlign="center" width="100" allowSort="true" >商品描述</div>
                        <div field="discount" align="center" headerAlign="center" width="50" allowSort="true" >商品折扣</div>
                        <div field="price" align="center" headerAlign="center" width="50" allowSort="true" >价格</div>
                        <div field="customize" renderer="customizeRenderer" align="center" headerAlign="center" width="70" allowSort="true" >能否订制</div>
                        <div field="stock" align="center" headerAlign="center" width="50" allowSort="true" >库存</div>
                        <div field="createdAt" width="100" align="center" headerAlign="center"  allowSort="true">创建日期</div>
                        <div field="updatedAt" width="100" align="center" headerAlign="center"  allowSort="true">更新日期</div>
                    </div>
                </div>
            </div>
        </div>
        <div style="text-align:left;padding-top:5px;padding-left:40px;" colspan="6">
            <a class="Update_Button" href="javascript:updateRow();">提交</a>
            <a class="Cancel_Button" href="javascript:cancelRow();">取消</a>
        </div>
    </div>
</div>
</body>

<script type="text/javascript">
    var threadStatus = [{ id: -1, text: '删除' },{ id: 0, text: '关闭' },{ id: 1, text: '开启' },{ id: 2, text: ' ' }];
    var threadIsShare = [{ id: 0, text: '否' },{ id: 1, text: '是' }];
    var picArray = [];
    var picArrayB = [];
    mini.parse();
    var editForm = document.getElementById("editForm1");
    var grid = mini.get("datagrid1");
    var grid2 = mini.get("datagrid2");
    var grid3 = mini.get("datagrid3");
    grid.load();
    grid.on("drawcell", function (e) {
        var value = e.value;
        var column = e.column;
        if (column.field == "status") {
            parseInt(value)
            if(value == 0) {
                e.cellHtml = '<text>删除</text>';
            }else if(value == 1) {
                e.cellHtml = '<text>正常</text>';
            }
        } else if (column.field == "isCanShare") {
            parseInt(value)
            if(value == 0) {
                e.cellHtml = '<text>不能</text>';
            }else if(value == 1) {
                e.cellHtml = '<text>可以</text>';
            }
        } else if (column.field == "isTop") {
            if(value) {
                e.cellHtml = '<text>是</text>';
            }else{
                e.cellHtml = '<text>否</text>';
            }
        }
        if (column.field == "picName") {
            if(value) {
                e.cellHtml = '<img class="bigImg" onclick="bigImg(this)" src="'+value+'" width="30" height="30" alt="图片">';
            }else{
                e.cellHtml = '<img class="bigImg" onclick="bigImg()"  src="http://7xiuo5.com1.z0.glb.clouddn.com/fgImage.png" width="30" height="30">';
            }
        }
    });
    function bigImg(that) {
        var row = grid.getSelected();
        if (row) {
                $("#imgId").attr('src', that.src);
                $("#outImg").css('display','block');
        }
    };
    function smallImg() {
        $("#outImg").css('display','none');
    };
    function search() {
        var userOId = mini.get("userOId").getValue();
        var objectId = mini.get("objectId").getValue();
        var tribeOId = mini.get("tribeOId").getValue();
        var tribeName = mini.get("tribeName").getValue();
        var nickName = mini.get("nickName").getValue();
        var content = mini.get("content").getValue();

        grid.load({
            userOId: userOId,
            tribeOId:tribeOId,
            tribeName:tribeName,
            nickName:nickName,
            objectId:objectId,
            content:content,
        });

    }
    $("#objectId,#tribeOId,#tribeName,#creater,#nickName,#content").bind("keydown", function (e) {
        if (e.keyCode == 13) {
            search();
        }
    });
    function onShowRowDetail(e) {
        var row = e.record;
        var td = grid.getRowDetailCellEl(row);
        td.appendChild(editForm);
        editForm.style.display = "";
        //表单加载员工信息
        var tribeGoodsOIds = row.tribeGoodsOIds.join("-");
        var fightGoodsOIds = row.fightGoodsOIds.join("-");
        var form = new mini.Form("editForm1");
        mini.getbyName("content").setValue(row.content);
        grid2.load({"objectId":tribeGoodsOIds});
        grid3.load({"objectId":fightGoodsOIds});
        grid2.on("drawcell", function (e) {
            var  value = e.value;
            column = e.column;
            //将性别文本替换成图片
            if (column.field == "shopIcon") {
                if(value) {
                    e.cellHtml = '<img class="bigImg" onclick="bigImg(this)" src="' + value + '?imageMogr2/thumbnail/640x/format/jpg/interlace/1/auto-orient" width="30" height="30" alt="图片">';
                }else{
                    e.cellHtml = '<img class="bigImg" onclick="bigImg()"  src="http://7xiuo5.com1.z0.glb.clouddn.com/fgImage.png?imageMogr2/auto-orient/thumbnail/!100x100r/gravity/Center/crop/100x100/quality/80/auto-orient" width="30" height="30" alt="图片">';
                }
            }
        });
        grid3.on("drawcell", function (e) {
            var  value = e.value;
            column = e.column;
            //将性别文本替换成图片
            if (column.field == "shopIcon") {
                if(value) {
                    e.cellHtml = '<img class="bigImg" onclick="bigImg(this)" src="' + value + '?imageMogr2/thumbnail/640x/format/jpg/interlace/1/auto-orient" width="30" height="30" alt="图片">';
                }else{
                    e.cellHtml = '<img class="bigImg" onclick="bigImg(this)"  src="http://7xiuo5.com1.z0.glb.clouddn.com/fgImage.png?imageMogr2/auto-orient/thumbnail/!100x100r/gravity/Center/crop/100x100/quality/80/auto-orient" width="30" height="30" alt="图片">';
                }
            }
        });
    };
    function showAudio() {
        var row = grid.getSelected();
        var streamId = row.streamId;
        mini.open({
            url: "/tribeRoute/tribeThreadPlayer?&objectId="+streamId,
            title: "播放音频", width: 420, height: 100,

            ondestroy: function (action) {

                grid.reload();

            }
        });
    }
    function bigImgArray(e) {
//    console.log(e.src);
        var imagePath = e.src;
        $("#imgId").attr('src', imagePath);
        $("#outImg").css('display','block');
    };
    function cancelRow() {
        grid.reload();
    }

    function updateRow() {
        var form = new mini.Form("editForm1");
        var data = form.getData();
        grid.loading("保存中，请稍后......");
//    var json = mini.encode(data);
        $.ajax({
            url: "/tribeRoute/tribeThreadUpdate",
            type:'POST',
            data: data,
            success: function (result) {
                alert(result);
                grid.reload();
            },
            error: function (jqXHR, textStatus, errorThrown) {
                alert(jqXHR.responseText);
            }
        });

    }

    function statusRenderer(e) {
        var value = e.value;
        if (value==-1) {
            return (value, '删除')
        }else if(value==0){
            return (value, '下架')
        }else if(value==1){
            return (value, '上架')
        }else {
            return (value, '隐藏')
        }
    }
    function groupBuyingRenderer(e) {
        var value = e.value;
        if (value==1) {
            return (value, '可以')
        }else if(value==0){
            return (value, '不可以')
        }
    }
    function recommendRenderer(e) {
        var value = e.value;
        if (value==1) {
            return (value, '已推荐')
        }else if(value==0){
            return (value, '未推荐')
        }
    }
    function freePostRenderer(e) {
        var value = e.value;
        if (value==1) {
            return (value, '包邮')
        }else if(value==0){
            return (value, '不包邮')
        }
    }
    function customizeRenderer(e) {
        var value = e.value;
        if (value==1) {
            return (value, '可以定制')
        }else if(value==-1){
            return (value, '不能定制')
        }
    }
    function remove() {
        var rows = grid.getSelecteds();
        if (rows.length > 0) {
            if (confirm("确定删除选中记录？")) {
                var ids = [];
                for (var i = 0, l = rows.length; i < l; i++) {
                    var r = rows[i];
                    var objectId = r.objectId.replace("\"","");
                    ids.push(objectId);
                }
                var id = ids.join('-');
                grid.loading("操作中，请稍后......");
                $.ajax({
                    url: "/tribeRoute/child/brand/delete" ,
                    type:"POST",
                    data:{id:id},
                    success: function (text) {
                        grid.reload();
                    },
                    error: function () {
                    }
                });
            }
        } else {
            alert("请选中一条记录");
        }
    }
</script>
</html>